//
//  AnimationDemo.swift
//  SwiftUIDemo
//
//  Created by Tilt Wang on 2025/6/28.
//

import SwiftUI

struct AnimationDemo: View {
    @State var isAnimated: Bool = false
    var body: some View {
        VStack {
            Button("Button") {
//                withAnimation(
//                    Animation
//                        .default
////                        .delay(0.2)
////                        .repeatCount(5, autoreverses: false)
//                        .repeatForever (autoreverses: true)
//                ) {
//                    isAnimated.toggle()
//                }
                isAnimated.toggle()
            }
            Spacer()
            RoundedRectangle(cornerRadius: isAnimated ? 50 : 25)
                .fill(isAnimated ? .red : .green)
                .frame(width: isAnimated ?  100 : 300, height: isAnimated ? 100 : 200)
                .rotationEffect(Angle(degrees: isAnimated ? 160 : 0))
                .offset(y: isAnimated ? 300: 0)
                .animation(Animation
                    .default
//                        .delay(0.2)
//                        .repeatCount(5, autoreverses: false)
                    .repeatForever (autoreverses: true))
            Spacer()
        }
    }
}

#Preview {
    AnimationDemo()
}
